test_hypotheses <- function(.data) {
  profile_pairs <- .data

  out1 <- profile_pairs %>%
    group_by(pair) %>%
    reframe(tidy(lm_robust(selected ~ 1, data = pick(everything()))))

  out2 <- lm_robust(selected ~ pair, data = profile_pairs) %>%
    tidy() %>%
    filter(term != "(Intercept)")

  out3 <- profile_pairs %>%
    group_by(pair, experiment) %>%
    reframe(tidy(lm_robust(selected ~ 1, data = pick(everything()))))

  out4 <- profile_pairs %>%
    group_by(experiment) %>%
    reframe(tidy(lm_robust(selected ~ pair, data = pick(everything())))) %>%
    filter(term == "pair") %>%
    mutate(type = case_when(
      experiment == "Public school" ~ 1,
      experiment == "Private company" ~ 2
    ))

  g1 <- ggplot(out1) +
    geom_hline(
      yintercept = 0.5,
      linetype = "dashed",
      color = "gray"
    ) +
    geom_pointrange(aes(
      x = pair,
      y = estimate,
      ymin = conf.low,
      ymax = conf.high
    )) +
    geom_text(
      aes(
        x = pair,
        y = estimate,
        label = format(round(estimate, digits = 2), nsmall = 2)
      ),
      vjust = -1
    ) +
    scale_x_continuous(
      limits = c(0.5, 2.5),
      breaks = c(1, 2),
      labels = c(
        "Japanese vs.\nZainichi (in Japanese)",
        "Japanese vs.\nZainichi (in Korean)"
      )
    ) +
    theme_few() +
    coord_flip() +
    labs(
      title = "Marginal Mean",
      y = " ",
      x = NULL
    )

  g2 <- ggplot(out2) +
    geom_hline(
      yintercept = 0,
      linetype = "dashed",
      color = "gray"
    ) +
    geom_pointrange(aes(
      x = 1,
      y = estimate,
      ymin = conf.low,
      ymax = conf.high
    )) +
    geom_text(
      aes(
        x = 1,
        y = estimate,
        label = format(round(estimate, digits = 2), nsmall = 2)
      ),
      vjust = -1
    ) +
    coord_flip() +
    scale_x_continuous(
      limits = c(0.5, 1.5),
      breaks = c(1),
      labels = c("Difference in\n Marginal Means")
    ) +
    theme_few() +
    labs(
      title = "Average Marginal Component Effect",
      y = "Estimate",
      x = NULL
    )

  g3 <- ggplot(out3) +
    geom_hline(
      yintercept = 0.5,
      linetype = "dashed",
      color = "gray"
    ) +
    geom_pointrange(aes(
      x = pair,
      y = estimate,
      ymin = conf.low,
      ymax = conf.high
    )) +
    facet_wrap(~experiment, nrow = 2) +
    geom_text(
      aes(
        x = pair,
        y = estimate,
        label = format(round(estimate, digits = 2), nsmall = 2)
      ),
      vjust = -1
    ) +
    scale_x_continuous(
      limits = c(0.5, 2.5),
      breaks = c(1, 2),
      labels = c(
        "Japanese vs.\nZainichi (in Japanese)",
        "Japanese vs.\nZainichi (in Korean)"
      )
    ) +
    theme_few() +
    coord_flip() +
    labs(
      title = "Marginal Means by Experiment Type",
      y = " ",
      x = NULL
    )

  g4 <- ggplot(out4) +
    geom_hline(
      yintercept = 0,
      linetype = "dashed",
      color = "gray"
    ) +
    geom_pointrange(aes(
      x = type,
      y = estimate,
      ymin = conf.low,
      ymax = conf.high
    )) +
    geom_text(
      aes(
        x = type,
        y = estimate,
        label = format(round(estimate, digits = 2), nsmall = 2)
      ),
      vjust = -1
    ) +
    coord_flip() +
    scale_x_continuous(
      limits = c(0.5, 2.5),
      breaks = c(1, 2),
      labels = c("Public School", "Private Company")
    ) +
    theme_few() +
    labs(
      title = "Average Marginal Component Effect by Experiment Type",
      y = "Estimate",
      x = NULL
    )

  out1 <- g1 / g2 + plot_layout(heights = c(2, 1))
  out2 <- g3 / g4 + plot_layout(heights = c(2, 1))

  list(out1, out2)
}
